const express = require("express");
const {
  getAllMenu,
  addMenu,
  deleteMenu,
  updateMenu,
} = require("../../router_handler/admin/menu");
const router = express.Router();

// 获取所有菜单
router.get("/allMenus", async (req, res) => {
  const result = await getAllMenu();
  res.send(result);
});
// 添加菜单
router.post("/save", async (req, res) => {
  const { name, parent_id } = req.body;
  const result = await addMenu(name, parent_id);
  res.send(result);
});
// 修改菜单
router.put("/update", async (req, res) => {
  const { id, name } = req.body;
  const result = await updateMenu(id, name);
  res.send(result);
});
// 删除菜单
router.delete("/remove/:id", async (req, res) => {
  const { id } = req.params;
  const result = await deleteMenu(id);
  res.send(result);
});
module.exports = router;
